/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <cstdlib>
#include <algorithm>
const int M=20;
using namespace std;
int num,Per[M],table[M]={0},cnt=0;
void permutation(int index)
{
    if (index==num+1)
    {
        ++cnt;
        return;
    }
    for (int x=1;x<=num ;++x )
    {
        if (table[x]==0)
        {
            bool flag=true;
            for (int pre=1;pre<index;++pre )
            {
                if (abs(index-pre)==abs(x-Per[pre]))
                {
                    flag=false;
                    break;
                }
            }
            if (flag)
            {
                Per[index]=x;
                table[x]=1;
                permutation(index+1);
                table[x]=0;
            }
        }
    }
}
int main_98()
{
    num=8;
    permutation(1);
    printf("%d\n",cnt);
    int arr[]={1,2,3,4,5};
    do
    {
        for (int i=0;i<5 ;++i )
        {
            printf("%d",arr[i]);
        }
        printf("\n");
    } while (next_permutation(arr,arr+5));
	return 0;
}
